<!--
 * 课程分类管理
 * ============================================================================
 * 版权所有 2015-2017 风影随行，并保留所有权利。
 * 网站地址: http://www.haoshu888.com
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！不允许对程序代码以任何形式任何目的的再发布，作者将保留
 * 追究法律责任的权力和最终解释权。
 * ============================================================================
-->
{template 'common/header'}
<ul class="nav nav-tabs">
    <li {if $op=='display'}class="active"{/if}><a href="{php echo $this->createWebUrl('category');}">分类列表</a></li>
    <li {if $op=='post'}class="active"{/if}><a href="{php echo $this->createWebUrl('category', array('op'=>'post', 'id'=>$_GPC['id']));}">{if $_GPC['id']>0}编辑{else}添加{/if}分类</a></li>
</ul>
{if $operation == 'display'}
<style type="text/css">
.form-controls{display: inline-block; width:70px;}
.cblock{display:block !important;}
.cnone{display:none !important;}
</style>
<link rel="stylesheet" type="text/css" href="{MODULE_URL}template/style/category.css">
<div class="main">
    <div class="category">
        <form action="" method="post">
            <div class="panel panel-default">
                <div class="panel-body table-responsive">
					<div class="dd" id="div_nestable">
						{loop $category $row}
						<ol class="dd-list" style="margin-bottom:15px;">
							<li class="dd-item">
								<button data-action="collapse" id="collapse{$row['id']}" type="button" style="display:none;" onclick="collapse({$row['id']});">Collapse</button>
								{if !empty($row['son'])}
								<button data-action="expand" id="expand{$row['id']}"   type="button" style="display: block;" onclick="expand({$row['id']});">Expand</button>
								{else}
								<button data-action="collapse" type="button" style="display: block;">collapse</button>
								{/if}
								
								<div class="dd-handle" style="width:100%;background:#eff5e9;">
									<input type="text" class="form-control" name="category[{$row['id']}]" value="{$row['displayorder']}" style="width: 70px;display:inline-block;">&nbsp;&nbsp;
									<img src="{if !empty($row['ico'])}{$_W['attachurl']}{$row['ico']}{else}{MODULE_URL}template/mobile/images/nopic.png{/if}" width="30" height="30"> &nbsp;&nbsp;[ID: {$row['id']}] {$row['name']}
									<span class="pull-right">
										{if $row['is_show']==1}
										<a href="{php echo $this->createWebUrl('category',array('op'=>'changeShow','id'=>$row['id']));}" class="btn btn-success btn-sm" style="padding:2px 10px;" title="点击隐藏分类">显示</a>
										{else}
										<a href="{php echo $this->createWebUrl('category',array('op'=>'changeShow','id'=>$row['id']));}" class="btn btn-default btn-sm" style="padding:2px 10px;" title="点击显示分类">隐藏</a>
										{/if}
										<a class="btn btn-default btn-sm" href="{php echo $this->createWebUrl('category', array('op' => 'post', 'id' => $row['id']))}" title="修改"><i class="fa fa-edit"></i></a>
										<a class="btn btn-default btn-sm" href="{php echo $this->createWebUrl('category', array('op' => 'delete', 'id' => $row['id']))}" title="删除" onclick="return confirm('该操作不可恢复，确定删除？');return false;"><i class="fa fa-remove"></i></a>
									</span>
								</div>
								{loop $row['son'] $son}
								<ol class="dd-list cid{$row['id']}" style="width:100%;display:none;">
									<li class="dd-item">
										<div class="dd-handle">
											<input type="text" class="form-control" name="son[{$son['id']}]" value="{$son['displayorder']}" style="width: 70px;display:inline-block;">&nbsp;&nbsp;
											<img src="{if !empty($son['ico'])}{$_W['attachurl']}{$son['ico']}{else}{MODULE_URL}template/mobile/images/nopic.png{/if}" width="30" height="30"> &nbsp;&nbsp;[ID: {$son['id']}] {$son['name']}
											<span class="pull-right">
												{if $son['is_show']==1}
												<a href="{php echo $this->createWebUrl('category',array('op'=>'changeShow','id'=>$son['id']));}" class="btn btn-success btn-sm" style="padding:2px 10px;" title="点击隐藏分类">显示</a>
												{else}
												<a href="{php echo $this->createWebUrl('category',array('op'=>'changeShow','id'=>$son['id']));}" class="btn btn-default btn-sm" style="padding:2px 10px;" title="点击显示分类">隐藏</a>
												{/if}
												<a class="btn btn-default btn-sm" href="{php echo $this->createWebUrl('category', array('op' => 'post', 'id' => $son['id']))}" title="修改"><i class="fa fa-edit"></i></a>
												<a class="btn btn-default btn-sm" href="{php echo $this->createWebUrl('category', array('op' => 'delete', 'id' => $son['id']))}" title="删除" onclick="return confirm('该操作不可恢复，确定删除？');return false;"><i class="fa fa-remove"></i></a>
											</span>
										</div>
									</li>
								</ol>
								{/loop}
							</li>
						</ol>
						{/loop}
						<table class="table">
							 <tbody>
								 <tr>
									 <td>
										 <input name="submit" type="submit" class="btn btn-primary" value="批量排序">
										 <input type="hidden" name="token" value="{$_W['token']}">
									 </td>
								 </tr>
							 </tbody>
						</table>
					</div>
					{$pager}
				</div>
			</div>
		</form>
	</div>
</div>
<script type="text/javascript">
function collapse(obj){
	$("#collapse"+obj).hide();
	$("#expand"+obj).show();
	$(".cid"+obj).hide();
}
function expand(obj){
	$("#expand"+obj).hide();
	$("#collapse"+obj).show();
	$(".cid"+obj).show();
}
</script>
{elseif $operation == 'post'}
<div class="main">
	<form action="" method="post" class="form-horizontal form" enctype="multipart/form-data">
        <div class="panel panel-default">
            <div class="panel-heading">
                分类信息
            </div>
            <div class="panel-body">
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">上级分类</label>
                    <div class="col-sm-9">
                        <select name="parentid" class="form-control">
							<option value="0" {if empty($category['parentid'])}selected{/if}>顶级分类</option>
							{loop $list $item}
							<option value="{$item['id']}" {if $category['parentid']==$item['id']}selected{/if}>{$item['name']}</option>
							{/loop}
						</select>
                    </div>
                </div>
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">分类名称</label>
                    <div class="col-sm-9">
                        <input type="text" name="catename" class="form-control" value="{$category['name']}" />
                    </div>
                </div>
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">分类图标</label>
                    <div class="col-sm-9">
                        {php echo tpl_form_field_image('ico', $category['ico']);}
						<span>建议尺寸200px * 200px</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">排序</label>
                    <div class="col-sm-9">
                        <input type="text" name="displayorder" class="form-control" value="{$category['displayorder']}" />
                    </div>
                </div>
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否显示</label>
                    <div class="col-sm-9">
                        <label class="radio-inline"><input type="radio" name="is_show" value="1" {if $category['is_show']==1}checked{/if} /> 显示</label>
                        &nbsp;
                        <label class="radio-inline"><input type="radio" name="is_show" value="0" {if $category['is_show']==0}checked{/if} /> 隐藏</label>
                        <span class="help-block"><strong></strong>一级分类支持在手机端前台和所有分类页控制显示，二级分类仅支持在所有分类页控制显示</span>
                    </div>
                </div>
				<div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">分类链接</label>
                    <div class="col-sm-9">
                        <div style="padding-top:8px;font-size: 14px;"><a href="javascript:;" id="copy-btn">{$_W['siteroot']}app/{php echo str_replace("./", "", $this->createMobileUrl('search', array('cat_id'=>$category['id'])));}</a></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group col-sm-12">
            <input type="submit" name="submit" value="保存" class="btn btn-primary col-lg-1" />
            <input type="hidden" name="token" value="{$_W['token']}" />
			<input type="hidden" name="id" value="{$id}" />
        </div>
	</form>
</div>
<script type="text/javascript">
require(['jquery', 'util'], function($, util){
	$(function(){
		util.clip($("#copy-btn")[0], $("#copy-btn").text());
	});
});
</script>
{/if}
{template 'common/footer'}